package com.kefu.web.im.netty.event.handler.multiupdate;

import com.kefu.web.im.netty.event.MultiUpdateEvent;
import com.kefu.web.im.netty.event.UserDataEvent;
import com.lmax.disruptor.RingBuffer;

/**
 * 事件监听
 * 
 * @author chenkw
 *
 */
public class MultiUpdateEventProducer {
	private final RingBuffer<UserDataEvent> ringBuffer;

	public MultiUpdateEventProducer(RingBuffer<UserDataEvent> ringBuffer) {
		this.ringBuffer = ringBuffer;
	}

	public void onData(MultiUpdateEvent event) {
		long id = ringBuffer.next(); // Grab the next sequence
		try {
			UserDataEvent multiEventData = ringBuffer.get(id);
			multiEventData.setEvent(event);
		} finally {
			ringBuffer.publish(id);
		}
	}
}
